package com.xinz.ttmall;

import com.taobao.api.ApiException;
import com.taobao.api.DefaultTaobaoClient;
import com.taobao.api.TaobaoClient;
import com.taobao.api.request.UserGetRequest;
import com.taobao.api.response.UserGetResponse;
import com.xinz.Constants;

public class TTMallApiTest {

//	public static void main(String[] args) {
//		TaobaoClient client = new DefaultTaobaoClient(Constants.API_URL, Constants.APP_KEY, Constants.APP_SECRET);
//		UserGetRequest req = new UserGetRequest();
//		req.setFields("user_id");
//		req.setNick("xinz880526");
//		try {
//			UserGetResponse response = client.execute(req);
////			System.out.println(response.getParams().get("user_id") + "\n" + response.getBody());
//		} catch (ApiException e) {
////			e.printStackTrace();
//		}
//	}
	
//	 protected static String url = "http://gw.api.tbsandbox.com/router/rest";//沙箱环境调用地址
	 protected static String url = "http://gw.api.taobao.com/router/rest";// 正式环境调用地址
     //正式环境需要设置为:http://gw.api.taobao.com/router/rest
//     protected static String appkey = "test";
     protected static String appkey = Constants.APP_KEY;
//     protected static String appSecret = "test";
     protected static String appSecret = Constants.APP_SECRET;
     public static void testUserGet() {
         TaobaoClient client = new DefaultTaobaoClient(url, appkey, appSecret);//实例化TopClient类
         UserGetRequest req = new UserGetRequest();//实例化具体API对应的Request类
         req.setFields("nick,sex,buyer_credit,seller_credit ,created,last_visit");
         req.setNick("andyy_tan");
         UserGetResponse response;
         try {
             response = client.execute(req); //执行API请求并打印结果
             System.out.println("result:"+response.getBody());
             System.out.println("nick:"+response.getUser().getNick());
         } catch (ApiException e) {
         // deal error
         }
     }
     public static void main(String[] args) {
         testUserGet();
     }
}
